Imports System
Imports System.Xml

''CONVERTED

Public Class PartiesMsg
    Inherits BaseMsg

    'You can also run a Party Detail List Request for all Trading Firms related to your Broker Firm.
    '<PtyDetlListReq ReqID="123437">
    '    <Hdr SID="RCBK" SSub="rcaf" TID="CME" TSub="CPAPI"/>
    '    <ReqPty ID="RCAF_BRKR" R="30"/>
    '    <ReqR R="7"/>
    '</PtyDetlListReq>

    'As well as a Party Detail List Request for all Clearing Firms related to your Broker Firm.
    '<PtyDetlListReq ReqID="123437">
    '   <Hdr SID="RCBK" SSub="rcaf" TID="CME" TSub="CPAPI"/>
    '   <ReqPty ID="RCAF_BRKR" R="30"/>
    '   <ReqR R="1"/>
    '</PtyDetlListReq>
	Protected m_firm As String

    Public Property FirmID() As String
        Get
            Return m_firm
        End Get
        Set(ByVal Value As String)
            m_firm = Value
        End Set
    End Property

    Public Sub New()
        RequestType = "PtyDetlListReq"
        ResponseType = "PtyDetlListRpt"
    End Sub

    Protected Overrides Function RequestMsg(ByRef XmlW As XmlTextWriter) As Boolean

        XmlW.WriteStartElement("ReqPty")

		XmlW.WriteAttributeString("ID", Globals.CompanyID)
        XmlW.WriteAttributeString("R", "30")

        XmlW.WriteEndElement()

		XmlW.WriteStartElement("ReqR")

		XmlW.WriteAttributeString("R", m_reqtyp)

        XmlW.WriteEndElement()

        Return True
    End Function

    Protected Overrides Sub ResponseParse(ByRef node As XmlNode)

        Dim ptygrp As XmlNode

		For Each ptygrp In node.ChildNodes
			If ptygrp.Name = "PtyDetl" Then
				InsertTrader(ptygrp)
			End If
		Next

    End Sub

    Private Sub InsertTrader(ByRef party As XmlNode)
        '            <Pty R="1" ID="abn"/>
        '            <Pty ID="tmcgrath" R="12">
        '                  <Sub ID="Thomas McGrath" Typ="9"/>
        '            </Pty>

        Dim dbi As dbInterface = Globals.dbi
        Dim ptysub As XmlNode

        Dim id As String = ""
		Dim nm As String = ""

        If party.Name = "PtyDetl" Then
            id = party.Attributes("ID").InnerText

			If party.ChildNodes.Count > 0 Then
				For Each ptysub In party.ChildNodes
					If ptysub.Name = "Sub" Then
						nm = ptysub.Attributes("ID").InnerText
					End If
				Next
			End If

			Dim strsql As String

			strsql = "insert into nymx_firm_data (firm_id, firm_name, firm_type) values ("

			strsql &= dbi.quote(id) & ","
			strsql &= dbi.quote(nm) & ","
			strsql &= dbi.quote(ReqTyp) & ")"

			dbi.query(strsql)

		End If

    End Sub

End Class
